package com.hyc.entity;

import com.carrotsearch.sizeof.RamUsageEstimator;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.openjdk.jol.info.ClassLayout;
import org.openjdk.jol.info.GraphLayout;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class Person {
    private long id;
    private String name;
    private Integer age;
    private Person son;

    public static void main(String[] args) {
        Person son = new Person(100000000000L, "李二毛", 2, null);
        Person per = new Person(100000000001L, "赵钱孙", 30, son);
        System.out.println(RamUsageEstimator.sizeOf(per));

        System.out.println("================================================================================================");
        //打印实例的内存布局
        System.out.println(ClassLayout.parseInstance(per).toPrintable());
        System.out.println("=================================================");
        //打印对象的所有相关内存占用
        System.out.println(GraphLayout.parseInstance(per).toPrintable());
        System.out.println("=================================================");
        //打印对象的所有内存结果并统计
        System.out.println(GraphLayout.parseInstance(per).toFootprint());
    }
}
